<?php


namespace app\common\Cache;


use app\admin\model\About;
use app\common\CacheKey;

class AboutCache
{
    /**
     * 公告列表
     * @param $language
     * @param $page
     * @param $size
     * @return mixed
     */
    public static function getArticleList($language, $page, $size)
    {
        $key = sprintf(CacheKey::ARTICLE_LIST, $language . $page . $size);
        $list = json_decode(redis()->get($key), true);
        if (empty($list) || $list == 'null') {
            $where = ['language' => $language, 'type' => 1];
            $field = ['id', 'title', 'cover_image', 'introduce', 'author', 'pub_time'];
            $list = (new About())->articleList($where, $page, $size, $field);
            redis(2)->set($key, json_encode($list), 86400);
        }
        return $list;
    }

    /**
     * 删除公告缓存
     */
    public static function delAboutCache()
    {
        redis(2)->del(redis(2)->keys("about:article_list_*"));
    }
}